﻿using Library.Common;
using Library.Common.Helper;
using LogForParameter.IServices;
using Quartz;
using QuartzTest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace LogForParameter.Api.Controllers.JobInstance
{
    public static class QuartzAutoHelp
    {
        public static async void QuartzAutoSetUp(IQuartzServer quartzServer)
        {
            quartzServer.Start().Wait();
            var jobDetail = JobBuilder.Create(typeof(ASMJOB)).SetJobData(new JobDataMap { new System.Collections.Generic.KeyValuePair<string, object>("ActivityId", 1) }).WithIdentity("activity_startnotice","activity").Build();//可以不带参数
            int repeatCount = Appsettings.App(new string[] { "Quartz", "RepeatCount" }).ObjToInt();
            int Interval = Appsettings.App(new string[] { "Quartz", "Interval" }).ObjToInt();
            var triggerBulder = TriggerBuilder.Create().StartNow().WithIdentity("activityNotice").WithSimpleSchedule(m => {
                m.WithIntervalInSeconds(Interval);
                m.RepeatForever();
            });
            var trigger = triggerBulder.Build();
            await quartzServer.AddJob(jobDetail, trigger);
        }
    }
}
